package com.test.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by Administrator on 2017/5/3.
 * rabbitMQ测试---生成者
 */
@Component
public class Sender {
    private static final Log log = LogFactory.getLog(Sender.class);

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Transactional
    public void send(String data){
        data = data + new Date();
        System.out.println("preconvertAndSend======" + new Date());
        System.out.println("data======" + data);
//        databaseprocess();
        this.rabbitTemplate.convertAndSend("hello",data);
        System.out.println("proconvertAndSend======" + new Date());
        throw new RuntimeException();

    }

    private void databaseprocess() {
        throw new RuntimeException();
    }
}
